using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Drawing;

namespace UmlDesigner.Model
{
    [Serializable]
    class Document
    {
        public bool isModified = false;

        internal List<ItemWidget> items = new List<ItemWidget>();

        internal void MergeDocument(Document document)
        {
            items.InsertRange(0, document.items);
        }

        internal void GenerateCode(CodeGenerationSettings settings, List<ItemWidget> rootSet)
        {
            foreach (ItemWidget item in rootSet)
            {
                if (item.IsClass() || item.IsFolder())
                {
                    try
                    {
                        settings.Errors.AppendLine("Generating code for " + item.GetClassName() + "...");
                        item.GenerateCode(settings);
                    }
                    catch (CodeGenerationException e)
                    {
                        settings.Errors.AppendLine(e.Message);
                    }
                }
            }
            settings.Errors.AppendLine("Code generation complete.");
        }

        internal void Dump(TreeNode parent)
        {
            foreach (ItemWidget item in items)
            {
                item.Dump(parent);
            }
        }

        private string name = "Class Diagram";

        internal string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }

        private Size documentSize;

        internal Size DocumentSize
        {
            get
            {
                return documentSize;
            }

            set
            {
                documentSize = value;
            }
        }


        internal int GetNumClasses()
        {
            int i = 0;
            foreach (ItemWidget item in items)
            {
                if (item.IsClass())
                {
                    i++;
                }
            }
            return i;
        }

        internal int GetNumNotes()
        {
            int i = 0;
            foreach (ItemWidget item in items)
            {
                if (item.IsNote())
                {
                    i++;
                }
            }
            return i;
        }

        internal int GetNumFolders()
        {
            int i = 0;
            foreach (ItemWidget item in items)
            {
                if (item.IsFolder())
                {
                    i++;
                }
            }
            return i;
        }

        internal int GetNumLinks()
        {
            int i = 0;
            foreach (ItemWidget item in items)
            {
                if (item.IsLink())
                {
                    i++;
                }
            }
            return i;
        }
    }
}
